#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import cv2
from pylab import *
from lib import *

# http://blog.csdn.net/jnulzl/article/details/47056937

canvas = np.zeros((31, 35,3), dtype='uint8')

res_rgb = cv2.imread('game.bmp')

for y in range(31):
    for x in range(35):
        canvas[y, x,0] = res_rgb[y, x,0]
        canvas[y, x,1] = res_rgb[y, x,1]
        canvas[y, x,2] = res_rgb[y, x,2]

res = cv2.matchTemplate(res_rgb, canvas, cv2.TM_CCOEFF_NORMED)
# 设置阈值,检查一定可以覆盖每一种水果图片
loc = np.where(res >= 0.8)
for pt in zip(*loc[::-1]):
    cv2.putText(res_rgb, 'x', (pt[0], pt[1] + 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1)
cv2.imwrite('c3.png', res_rgb)
